package com.elite.groovy.callback
import com.elite.groovy.util.EliteBean;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.elite.groovy.util.Util;
import net.sf.json.JSONObject;
/**
 *
 * @author luper
 *
 */

public class XbTaskStatus implements ServiceBackInvoke{
	public static final Log log = LogFactory.getLog(XbTaskStatus.class);
	private String charset = "gbk"; //设置字符集
	private int timeout = 100000; //设置请求超时时间
	private int enableSSLflag = 1;
	private String casecharset = "utf-8";
	private int caseenableSSLflag = 1;

	public String doCallBack(EliteBean eliteBean, HttpServletRequest request, HttpServletResponse response){
		log.debug("-----XbTaskStatus Begin Systeam----------");
		response.setHeader("Content-type", "text/html;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		Util u = new Util();
		String requestJSONStr =u.getRequestBody(request, "UTF-8");
		log.debug("requestJSONStr:" + requestJSONStr);


		eliteBean.update("insert into INTERFACE_JSONBODY values(sysdate,'8099', 'XbTaskStatus','"+requestJSONStr.toString()+"',sysdate,null)","dataSource");

	  
		JSONObject json  = new JSONObject().fromObject(requestJSONStr);
		
		String oldpolicy = json.getString("oldpolicy"); //上年保单号
		String frameno = json.getString("frameno"); //车架号


		if(oldpolicy == null || oldpolicy=='') {
			JSONObject jsonALL3 = new JSONObject();
			jsonALL3.put("retCode", "-1");
			jsonALL3.put("retMessage", "上年保单号不能为空！");
			return jsonALL3;
		}
		if(frameno == null || frameno=='') {
			JSONObject jsonALL3 = new JSONObject();
			jsonALL3.put("retCode", "-1");
			jsonALL3.put("retMessage", "车架号不能为空！");
			return jsonALL3;
		}

		
		def querysql11="select xbtaskstatus from (select c.callresultreason_id xbtaskstatus from  xb_cust_case t left join CUSTOMERCONTACT_HIS c on t.relation_id = c.objective_guid  where c.customercontact_his_guid is not null and t.policyno = '"+oldpolicy+"' and t.frameno = '"+frameno+"' order by createddate desc) where rownum=1 ";
		def list11=eliteBean.chaxun_sql(querysql11,"dataSource");
		if (list11 != null && list11.size() > 0) {
			def map11=list11[0];
			def xbtaskstatus=map11.get("xbtaskstatus");
			log.debug("xbtaskstatus-------------------------------"+xbtaskstatus);
			if(xbtaskstatus !="" && xbtaskstatus != null && !"null".equals(xbtaskstatus)){
				JSONObject jsonALL3 = new JSONObject();
				jsonALL3.put("retCode", "1");
				jsonALL3.put("retMessage", "success");
				jsonALL3.put("xbtaskstatus", xbtaskstatus);
				return jsonALL3;
			}else{
				JSONObject jsonALL3 = new JSONObject();
				jsonALL3.put("retCode", "0");
				jsonALL3.put("retMessage", "续保任务状态为空");
				return jsonALL3;
			}
		 }else{
			JSONObject jsonALL3 = new JSONObject();
			jsonALL3.put("retCode", "0");
			jsonALL3.put("retMessage", "未查到相关记录");
			return jsonALL3;
		 }

	}
}
